﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace ATM_Group3.Data
{
    public class Card :Connection
    {
        private String _cardID;
        private Int32 _pin;
        private DateTime _startDate;
        private String _status;
        private DateTime _expriredDate;
        private Account _account;
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter();

        public String CARDID
        {
            get { return _cardID; }
            set { _cardID = value; }
        }
        public Int32 PIN
        {
            get { return _pin; }
            set { _pin = value; }
        }
        public DateTime SDATE
        {
            get { return _startDate; }
            set { _startDate = value; }
        }
        public String STATUS
        {
            get { return _status; }
            set { _status = value; }
        }
        public DateTime DDATE
        {
            get { return _expriredDate; }
            set { _expriredDate = value; }
        }
        public Account ACCOUNT
        {
            get { return _account; }
            set { _account = null; }
        }

        public String GetPin(Card obj)
        {
           // DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand("Card_GetPin", Connect());
           // SqlDataAdapter da = new SqlDataAdapter();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@p1", obj.CARDID));
            da.SelectCommand = cmd;
            da.Fill(ds, "PIN");
            dt = ds.Tables["PIN"];
            string pin = dt.Rows[0]["PIN"].ToString();
            return pin;
        }
        public bool CheckCard(Card obj)
        {
            //DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand("Card_GetCardID", Connect());
           // SqlDataAdapter da = new SqlDataAdapter();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@p1", obj.CARDID));
            da.SelectCommand = cmd;
            da.Fill(ds, "Card");
            dt = ds.Tables["Card"];
            if (dt.Rows.Count > 0)
            {
                return true;
            }
            else {
                return false;
            }
            //string pin = dt.Rows[0]["Car"].ToString();
            //return pin;
        }
    }
}